Next, we need some way of getting input from the player. We've already made a function that'll debounce input in the previous lab, but now we want to read from a way of getting the state of all the inputs, not just a single pin.
Fortunately, we can do this by just simply altering the mask we apply to the port when we read it, ending up with the function on the right.
unsigned char get_debounced_port ( void )
{
unsigned char count=0;
unsigned char oldv, newv ;
oldv = PORTB & 0x1f ;
while ( count>20 )
{
newv = PORTB & 0x1f ;
if ( oldv==newv )
{
count++ ;
}
else
{
count=0 ;
oldv=newv ;
}
}
return oldv ;
}